package com.xmz.cacheaside.request;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentHashMap;

public class RequestQueue {

    private  List<ArrayBlockingQueue<Request>> queues=new ArrayList<>(10);

    /**
     * 标识位map
     * 如果有更新请求 true
     * 如果读请求 false
     */
    private Map<Integer, Boolean> flagMap = new ConcurrentHashMap<Integer, Boolean>();


    private static class Singleton{
        private static RequestQueue requestQueue;
        static{
            requestQueue=new RequestQueue();
        }

        public static RequestQueue getRequestQueue(){
            return requestQueue;
        }
    }

    public static RequestQueue getInstance(){
        return Singleton.getRequestQueue();
    }

    public void addQueue(ArrayBlockingQueue queue){
        this.queues.add(queue);
    }

    /**
     * 获取内存队列的数量
     * @return
     */
    public int queueSize() {
        return queues.size();
    }

    /**
     * 获取内存队列
     * @param index
     * @return
     */
    public ArrayBlockingQueue<Request> getQueue(int index) {
        return queues.get(index);
    }

    public Map<Integer, Boolean> getFlagMap() {
        return flagMap;
    }


}
